import pygame,sys,os
from Move_img import Move_img
class Spikes(Move_img):
    def __init__(self,tl_x,tl_y):
        self.image = pygame.image.load(self.resource_path('source/img/spike.png'))
        super().__init__(self.image,tl_x,tl_y,False)
        self.activate = False
    def spikes_move(self,person,dire,speed,check):
        horizontal_distance = abs(person.rect.centerx - self.rect.centerx)
        person_bottom = person.rect.bottom
        # 判断 人物的底部是否在（墙壁，墙壁加上人物高度）之间
        vertical_condition = (person_bottom <= self.rect.bottom) and (
                    person_bottom >= self.rect.top - person.rect.height)

        if horizontal_distance <= check and vertical_condition:
            self.activate = True

        if self.activate==True:
            self.img_move(dire,speed)
    def resource_path(self,relative_path):
        """ 根据打包后的环境动态加载资源路径 """
        if hasattr(sys, '_MEIPASS'):
            base_path = sys._MEIPASS
        else:
            base_path = os.path.abspath(".")
        return os.path.join(base_path, relative_path)